package com.tdkj.service.risevalue.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.risevalue.IBeanAdvertDao;
import com.tdkj.model.risevalue.BeanAdvert;
import com.tdkj.model.risevalue.BeanAdvertAuctionInfo;
import com.tdkj.model.risevalue.BeanAuctionRule;
import com.tdkj.service.BaseService;
import com.tdkj.service.risevalue.IBeanAdvertService;
            
@Component("advertService")
public class BeanAdvertServiceImpl extends BaseService implements IBeanAdvertService{
	
	private  IBeanAdvertDao beanAdvertDao;
	                              
	@Resource
	public void setBeanAdvertDao(IBeanAdvertDao beanAdvertDao) {
		this.beanAdvertDao = beanAdvertDao;
	}

	public IBeanAdvertDao getBeanAdvertDao() {
		return beanAdvertDao;
	}

	@Override
	public List<BeanAdvert> getAll() {
		return beanAdvertDao.findAll(BeanAdvert.class);
	}

	@Override
	public void delete(long id) {
		BeanAdvert bean = beanAdvertDao.findById(id, BeanAdvert.class);
		beanAdvertDao.delete(bean);
	}

	@Override
	public BeanAdvert get(long id) {
		return beanAdvertDao.findById(id, BeanAdvert.class);
	}

	@Override
	public void update(long id, String code, String name, String status,
			Map<String, String> properties) {
		
		BeanAdvert bean = beanAdvertDao.findById(id, BeanAdvert.class);
		bean.setCode(code);
		bean.setName(name);
		bean.setStatus(status);
		bean.setProperties(properties);
		
	}

	@Override
	public void add(String code, String name,
			Map<String, String> properties, Date auctionStartTime, Date auctionEndTime , Date useStartTime, Date useEndTime, long auctionRuleId) {
		
		BeanAuctionRule auctionRule = beanAdvertDao.findById(auctionRuleId, BeanAuctionRule.class);
		
		BeanAdvertAuctionInfo auctionInfo = new BeanAdvertAuctionInfo();
//		auctionInfo.setAuctionStartTime(auctionStartTime);
//		auctionInfo.setAuctionEndTime(auctionEndTime);
//		auctionInfo.setAuctionRule(auctionRule);
//		auctionInfo.setUseStartTime(useStartTime);
//		auctionInfo.setUseEndTime(useEndTime);
		
		properties = new HashMap<String,String>();
		properties.put("a", "b");
		properties.put("c", "d");
		
		BeanAdvert bean = new BeanAdvert();
		bean.setCode(code);
		bean.setName(name);
		bean.setProperties(properties);
	//	bean.setAuctionInfo(auctionInfo);
		
		beanAdvertDao.save(bean);
		
	}

	@Override
	public void publish(long id) {
		BeanAdvert advert = beanAdvertDao.findById(id, BeanAdvert.class);
		
		BeanAdvertAuctionInfo bean = new BeanAdvertAuctionInfo();
		bean.setAdvert(advert);
		
		beanAdvertDao.save(bean);
	}



}
